package com.kuaihuoyun.ctms.api;

import com.kuaihuoyun.ctms.dto.CtmsResponse;
import com.kuaihuoyun.ctms.entity.OrganizationEntity;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.http.POST;
import retrofit2.http.Query;

import java.io.IOException;
import java.util.List;

/**
 * Created by lxji on 2018/1/4.
 */
public class OrganizationService extends BaseService {
    public OrganizationService(String url, String token) {
        super(url, token);
    }

    public CtmsResponse<List<OrganizationEntity>> list() throws IOException {
        Call<CtmsResponse<List<OrganizationEntity>>> responseCall =
                retrofit.create(OrganizationApi.class).list(token);
        final Response<CtmsResponse<List<OrganizationEntity>>> response = responseCall.execute();
        if(!response.isSuccessful()) {
            return CtmsResponse.create(response);
        }

        return response.body();
    }

    interface OrganizationApi {
        @POST("/organization/list")
        Call<CtmsResponse<List<OrganizationEntity>>> list(@Query("access_token") String token) throws IOException;
    }
}
